package com.HospitalOutpatient.controller;

import com.HospitalOutpatient.annotation.LoginToken;
import com.HospitalOutpatient.dto.DoctorDutyDto;
import com.HospitalOutpatient.dto.DoctorIdAndDate;
import com.HospitalOutpatient.dto.DutyDto;

import com.HospitalOutpatient.entity.Duty;
import com.HospitalOutpatient.service.DutyService;
import com.HospitalOutpatient.utils.DateUtil;
import com.HospitalOutpatient.vo.DoctorDutyVo;
import com.HospitalOutpatient.vo.DutyIdAndPartialNum;
import com.HospitalOutpatient.vo.DutyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/duty")
public class DutyController {

    @Autowired
    private DutyService dutyService;
    @LoginToken
    @PostMapping("/updateDuty")
    public Result updateDuty(@RequestBody List<DutyDto> dutyList){
        boolean b = dutyService.addDuty(dutyList);
        if(b == false){
            return new Result(Code.SAVE_ERR,null,"添加排班失败");
        }
        return new Result(Code.SAVE_OK,null,"添加排班成功");
    }
    @LoginToken
    @PostMapping("/getAllDutyByIdAndDate")
    public Result getAllDutyByIdAndDate(@RequestBody DutyDto dutyDto){

        List<DutyVo> dutyVoList = dutyService.getDutyByIdandDate(dutyDto);

        return new Result(Code.GET_OK,dutyVoList,"选中日期排班信息");
    }
    @LoginToken
    @PostMapping("/getDoctorDutyByDateTime")
    public Result getAllDoctorDuty(@RequestBody DoctorDutyDto doctorDutyDto){

        List<DoctorDutyVo> doctorDutyVoList = dutyService.getDoctorDutyByDateAndOutpatientId(doctorDutyDto);

        return new Result(Code.GET_OK,doctorDutyVoList,"选中门诊日期的可挂号信息");

    }

    @LoginToken
    @PostMapping("/getDutyByDoctorIdAndTime")
    public Result getDutyByDoctorIdAndTime(@RequestBody DoctorIdAndDate doctorIdAndDate){

        Duty duty = new Duty();

        duty.setDoctorId(doctorIdAndDate.getDoctorId());
        duty.setDutyDate(DateUtil.dateToString(doctorIdAndDate.getDutyDate()));

        List<DutyIdAndPartialNum> dutyIdAndPartialNumList = dutyService.getDutyByDoctorIdAndTime(duty);
        return new Result(Code.GET_OK,dutyIdAndPartialNumList,"选中门诊日期的可挂号信息");
    }
}
